var KK = window.KK = {
	_ucurl:'http://passport.chuanke.com',
	_kkurl:'http://www.chuanke.com',
	_resurl:'http://res.ckimg.com',
	_answerUrl : 'http://wenda.chuanke.com',
	_kkdownload:'http://download.chuanke.com/client/KK.exe',
	_kkipad:'http://kk.chuanke.com/ipad',
	_kkiphone:'http://kk.chuanke.com/iphone',
	_kkandroid:'http://kk.chuanke.com/android',
	_uploadImgUrl : 'http://upload.img.chuanke.com',
	_uploadCourseware : 'http://web.v.chuanke.com/video.upload',
	_feedbackUrl : 'http://qingting.baidu.com/index.php?pid=171',
	//站点名称:index,uc,bbs
	_site:'index',
	_isHome:false,
	//第三方登录
	_sinaLogin:"http://passport.chuanke.com/login/auth?from=sina",
	_qqLogin:"http://passport.chuanke.com/login/auth?from=qq",
	_rrLogin:"http://passport.chuanke.com/login/auth?from=renren",
	_baiduLogin:"http://passport.chuanke.com/login/auth?from=baidu",
	//配置项
	_config:{
		broadCast : '',
		adminMenu : ''
	},
	//学生广播项(我的课程)
	_studentBroadCast:{
		todayCurrCourse : 0,	//今日直播
		handselCourse : 0,		//课程授权
		schoolComment : 0		//学校评价学生数
	},
	//老师广播项
	_teacherBroadCast:{
		schoolInvite : 0		//学校邀请加盟
	},
	//师长广播项
	_schoolBroadCast:{
		teacherApply	: 0,	//老师加盟申请
		refundApply		: 0,	//退款申请
		student1v1		: 0,		//新增1V1学生
		studentComment	: 0,	//学生评价课程数
		newOrderCnt		: 0		//新产生的订单数		
	},
	
	_messageItems : {
		courseMsgCnt:0,
		tradeMsgCnt:0,
		commentMsgCnt:0,
		systemMsgCnt:0,
		totalMsgCnt:0
	},
	
	user:{
		userid:0,
		username:'',
		nickname:'',
		cart:0
	},
	
	init : function(){
		if((typeof(iswap) == "undefined") || (iswap == 0) || (iswap == '') || (iswap == null) || (iswap == undefined)){
			var authinfo = this.readCookie("AuthInfo");
			if(typeof authinfo == "string"){
				try{
					var userinfo = eval('('+this.base64_decode(authinfo)+')'); 
					this.user.userid = userinfo.userid;
					this.user.username = userinfo.username;
					this.user.nickname = userinfo.nickname;
				}catch(e){}
			}
			var cartinfo = this.readCookie("CartInfo");
			if(typeof cartinfo == "string"){
				try{
					cart = eval('('+this.base64_decode(cartinfo)+')');
					this.user.cart = cart;
				}catch(e){}
			}
			this.buildHeaderBar();
			if (this.checkLogin()) {
				//我的课程红点及老师、学生、校长后台首页广播
				this.checkBroadCast();
				//学习记录
				$("#header-bar li.time").mouseover(function(){
					//alert('ddd');
				});
				//消息通知
				this.checkMessage();
				//购物车
				this.updateCartCount();
				//我的课程页面LEFT MENU
				if(KK._config.adminMenu == 'student'){
					this.buildStudentMenu();
				}else if(KK._config.adminMenu == 'teacher'){
					this.buildTeacherMenu();
				}else if(KK._config.adminMenu == 'seller'){
					this.buildSellerMenu();
				}
				
				$("#kk_header_message").parent('div.messages').show();
				//this.buildMessage();
				this.buildIdentifyMenu();
			}
			this.buildFooter();
		}	
	},
	
	buildFooter : function(){
		var footer = '';
		footer += '<nav class="ft_nav">';
		footer += '<a href="'+KK._kkurl+'/about" target="_blank">关于百度传课</a>';
		footer += '<a href="'+KK._kkurl+'/helpcenter/index.html" target="_blank">百度传课帮助</a>';
		if (this.user.userid > 0) {
			footer += '<a href="'+KK._feedbackUrl+'&kk_info='+this.user.userid+'" target="_blank">意见反馈</a>';
		} else {
			footer += '<a href="'+KK._feedbackUrl+'" target="_blank">意见反馈</a>';
		}
		
		footer += '<a href="'+KK._kkurl+'/contactus" target="_blank">联系方式</a>';
		footer += '<a href="'+KK._kkurl+'/job" target="_blank">招聘信息</a>';
		footer += '</nav>';
		footer += '<div class="copyright">';
		footer += '<p class="info"><span class="mr10">京ICP证<a href="http://www.miitbeian.gov.cn" target="_blank">130265</a>号</span>';
		footer += '<span class="mr10">Copyright &copy; 2015 </span>';
		footer += '<span>百度传课 <a target="_blank" href="http://www.chuanke.com/">Chuanke.com</a></span>';
		footer += '</p></div>';
		$('#footer').html(footer);
	},
	

	buildIdentifyMenu:function() {
		$.getScript(this._kkurl+"/?do=identify&r="+Math.random(), function(){
			//校长菜单
			var monitor_menu = '';
			if (is_monitor == 1) {
				monitor_menu += '<li><a href="'+KK._kkurl+'/?mod=seller">我是校长</a></li>';
				monitor_menu += '<li><a href="'+KK._kkurl+'/?mod=seller&act=course">课程管理</a></li>';
				monitor_menu += '<li><a href="'+KK._kkurl+'/?mod=seller&act=order">销售订单</a></li>';
				monitor_menu += '<li><a href="'+KK._kkurl+'/?mod=school&act=show&sid='+KK.user.userid+'">我的学校</a></li>';
				monitor_menu += '<li><a href="'+KK._kkurl+'/?mod=course&act=create&do=cate">发布课程</a></li>';
			} else {
				monitor_menu += '<li><a href="'+KK._kkurl+'/?mod=school&act=create">创建学校</a></li>';
			}
			$("#monitorMenu").html(monitor_menu);
			$("#userAvatar").attr("src",img_url);
			//老师菜单
			var teacher_menu = '';
			if (is_teacher == 1) {
				teacher_menu += '<li><a href="'+KK._kkurl+'/?mod=teacher">我是老师</a></li>';
				teacher_menu += '<li><a href="'+KK._kkurl+'/?mod=teacher&act=courseappoint">课程任命</a></li>';
				teacher_menu += '<li><a href="'+KK._kkurl+'/?mod=teacher&act=school">签约学校</a></li>';
			} else {
				teacher_menu += '<li><a href="'+KK._kkurl+'/?mod=teacher">申请老师</a></li>';
			}
			$("#teacher1").html(teacher_menu);
			
			
			//设置中心
			var set_menu = '';;
			set_menu += '<li><a href="'+KK._kkurl+'/?mod=student&act=index">我的课程</a></li>';
			set_menu += '<li><a href="'+KK._ucurl+'/info/detail">设置中心</a></li>';
			set_menu += '<li><a href="'+pay_url+'">支付中心</a></li>';
			set_menu += '<li class="line"><a href="'+KK._ucurl+'/remind">提醒设置</a></li>';
			set_menu += '<li><a href="'+prerecharge+'">充值</a></li>';
			set_menu += '<li><a href="'+KK._ucurl+'/login/logout">退出</a></li>';
			$("#setMenu").html(set_menu);
			
		});
	},
	
	buildHeaderBar:function() {
		var str = '<div class="wrapper">';

		/*头部导航左侧*/
		str += '<a  class="topR_logo" href="'+this._kkurl+'"></a>';
		str += '<ul class="topR_dev"><li class="liClient">';
		str += '<a href="javascript:;"><i class="icoR icoR_0"></i>下载传课</a><div style="display:none" class="hasChild" id="clientList"><div class="subC"><a href="http://kk.chuanke.com/" target="_blank">百度传课KK</a><a href="'+this._kkiphone+'" target="_blank">百度传课iPhone版</a><a href="'+this._kkipad+'" target="_blank">百度传课iPad版</a><a href="'+this._kkandroid+'" target="_blank">百度传课Android版</a></div></div>';
		str += '</li>';

		/*头部导航右侧*/
		str += '<li class="cart">';
		if(this.user.cart > 0){
			str += '<a href="'+this._kkurl+'/?mod=cart&act=show" id="kk_header_cart"><i class="icoR icoR_4"></i>购物车(<i id="cartCount">'+this.user.cart+'</i>)</a></li></ul>';
		}else{
			str += '<a href="'+this._kkurl+'/?mod=cart&act=show" id="kk_header_cart"><i class="icoR icoR_4"></i>购物车(<i id="cartCount">0</i>)</a></li></ul>';
		}
		
		str += '<div class="topR_search"><div class="inner"><span class="tp_label">';
		str += '<a href="javascript:;" id="searchType" stype="course">课程<i class="icoR icoR_5"></i></a><span class="tp_label_sub" id="searchTypeList" style="display:none;"><a href="javascript:;" id="courseType" stype="course">课程</a><a href="javascript:;" id="schoolType" stype="school">学校</a></span></span><span class="tp_txt">';
		if (this.user.userid > 0) {
			str += '<input type="text" style="width:173px;" id="head_searchKeywords" class="ipt" prompt="请输入关键词、学校名等...">';
		} else {
			str += '<input type="text" style="width:350px;" id="head_searchKeywords" class="ipt" prompt="请输入关键词、学校名等...">';
		}
		str += '<a class="tp_btn" href="javascript:;" title="搜索" id="head_searchSubmit"><i class="icoR icoR_6"></i></a></span></div></div>';
		
		//登陆信息
		var url = location.href;
		url = this.base64_encode(url);
		url = url.replace(/\//, '_');
		if (this.user.userid > 0) {
			//我是学生
			str += '<ul class="topR_nav"><li class="myCourse">';
			str += '<a href="'+this._kkurl+'/?mod=student&act=index">我的课程</a>';
			str += '<div class="hasChild">';
			str += '<ul class="ulNav">';
			str += '<li><a href="'+this._kkurl+'/?mod=student&act=index">学习首页</a></li>';
			str += '<li><a href="'+this._kkurl+'/?mod=student&act=course&do=timelist">直播日历</a></li>';
			str += '<li><a href="'+this._kkurl+'/?mod=student&act=course">我的课程</a></li>';
			str += '<li><a href="'+this._kkurl+'/?mod=student&act=collect">收藏的课程</a></li>';
			str += '<li><a href="'+this._kkurl+'/?mod=student&act=school">收藏的学校</a></li>';
			str += '</ul>';
			str += '</div></li>';
			//我是校长
			str += '<li class="seller curr">';
			str += '<a href="'+this._kkurl+'/?mod=seller">我是校长</a>';
			str += '<div class="hasChild">';
			str += '<ul class="ulNav" id="monitorMenu"></ul>';
			str += '</div></li>';
			//我是老师
			str += '<li class="teacher">';
			str += '<a href="'+this._kkurl+'/?mod=teacher">我是老师</a>';
			str += '<div class="hasChild">';
			str += '<ul class="ulNav" id="teacher1"></ul>';
			str += '</div></li>';
			str += '</ul>';
			
			
			
			str += '<ul class="topR_user">';
			//消息
			str += '<li class="msg">';
			str += '<a href="'+this._kkurl+'?mod=message&act=index&do=list" id="kk_header_message"><i class="icoR icoR_7"></i></a>';
			str += '<div class="hasChild">';
			str += '<ul class="msgSubList" id="header_messageDetail">';
			str += '<li class="line"><a href="'+this._kkurl+'/?mod=message&act=index&do=list&type=1">课程通知</a><i class="num msg_course">0</i></li>';
			str += '<li class="line"><a href="'+this._kkurl+'/?mod=message&act=index&do=list&type=2">交易通知</a><i class="num msg_trade">0</i></li>';
			str += '<li class="line"><a href="'+this._kkurl+'/?mod=message&act=index&do=list&type=3">评论</a><i class="num msg_comment">0</i></li>';
			str += '<li class="line"><a href="'+this._kkurl+'/?mod=message&act=index&do=list&type=4">系统消息</a><i class="num msg_system">0</i></li>';
			str += '<li class="clrTips"><a class="ml10" href="'+this._kkurl+'/?mod=message&act=index&do=list">更多&gt;</a>';
			str += '<span class="fr pt5 mr10"><a href="javascript:;" onclick="KK.clearMsgReminder()" class="n_btn24g">清除提醒</a></span></li>';
			str += '</ul>';
			str += '</div>';
			str += '</li>';
			//设置中心
			str += '<li class="photo">';
			str += '<a href="http://passport.chuanke.com/info/detail">';
			str += '<img id="userAvatar" width="40" height="40" alt="" src=""></a>';
			str += '<div class="hasChild"><ul class="ulUser" id="setMenu">';
			str += '</ul>';
			str += '</div></li>';
			str += '</ul>';
		} else{
			str += '<div class="topR_login">';
			str += '<a href="'+this._ucurl+'/login">马上登录</a>';
			str += '<a href="https://passport.baidu.com/v2/?reg&tpl=eduol&u="+encodeURIComponent(window.location.href)  target="_blank">注册</a>';
			str += '</div>';
		}
		str += '</div>';
		$('#header-bar').html(str);
	},
	
	updateCartCount:function() {
		$.ajax({
			url:this._kkurl+"/?mod=cart&act=operate&do=count&uid="+KK.user.userid+"&r="+Math.random(),
			type:"get",
			async:false,
			dataType:"script",
			success:function(){
				if(CartCnt > 0){
					$("#cartCount").text(CartCnt);
				}else{
					$("#cartCount").text(0);
				}
			}
		});
	},

	checkLogin:function() {
		if (this.user.userid > 0) {
			return true;
		} else {
			return false;
		}
	},
	
	checkMessage : function(){
		$.ajax({
			url : this._kkurl+"/?mod=message&_r="+Math.random(),
			type : "get",
			dataType : "jsonp",
			jsonp : "jsonpcallback",
			timeout : 5000,
			success : function(rs){
				KK._messageItems.courseMsgCnt = rs.courseMsgCnt;
				KK._messageItems.tradeMsgCnt = rs.tradeMsgCnt;
				KK._messageItems.commentMsgCnt = rs.commentMsgCnt;
				KK._messageItems.systemMsgCnt = rs.systemMsgCnt;
				KK._messageItems.totalMsgCnt = rs.totalMsgCnt;
				if(KK._messageItems.totalMsgCnt > 0){
					$("#header-bar li.msg").find("i.icoR").after('<i class="icoR icoR_10">'+KK._messageItems.totalMsgCnt+'</i>');
					$("#header-bar ul.msgSubList").find("i.msg_course").text(KK._messageItems.courseMsgCnt).after(rs.courseItem);
					$("#header-bar ul.msgSubList").find("i.msg_trade").text(KK._messageItems.tradeMsgCnt).after(rs.tradeItem);
					$("#header-bar ul.msgSubList").find("i.msg_comment").text(KK._messageItems.commentMsgCnt).after(rs.commentItem);
					$("#header-bar ul.msgSubList").find("i.msg_system").text(KK._messageItems.systemMsgCnt).after(rs.systemItem);
				}
			}
		});
	},
	
	clearMsgReminder : function(){
		$.ajax({
			url : this._kkurl+"/?mod=message&do=clearMsgReminder&_r="+Math.random(),
			type : "get",
			dataType : "jsonp",
			jsonp : "jsonpcallback",
			timeout : 5000,
			success : function(rs){
				if(rs.code > 0){
					KK._messageItems.courseMsgCnt = 0;
					KK._messageItems.tradeMsgCnt = 0;
					KK._messageItems.commentMsgCnt = 0;
					KK._messageItems.systemMsgCnt = 0;
					KK._messageItems.totalMsgCnt = 0;
					$("#header-bar li.msg").find("i.icoR").next("i.icoR_10").remove();
					$("#header-bar ul.msgSubList").find("i.msg_course").text(KK._messageItems.courseMsgCnt).next("ul").remove();
					$("#header-bar ul.msgSubList").find("i.msg_trade").text(KK._messageItems.tradeMsgCnt).next("ul").remove();
					$("#header-bar ul.msgSubList").find("i.msg_comment").text(KK._messageItems.commentMsgCnt).next("ul").remove();
					$("#header-bar ul.msgSubList").find("i.msg_system").text(KK._messageItems.systemMsgCnt).next("ul").remove();
				}
			}
		});
		return false;
	},
	
	checkBroadCast:function(){
		jQuery.support.cors = true;
		if(KK._config.broadCast == 'studentIndex'){
			$.ajax({
				url : this._kkurl+"/?mod=common&act=data&do=getStudentBroadCast&_r="+Math.random(),
				type : "get",
				dataType : "jsonp",
				jsonp : "jsonpcallback",
				timeout: 5000,
				success : function(rs){
					KK._studentBroadCast.todayCurrCourse = rs.todayCurrCourse;
					KK._studentBroadCast.handselCourse = rs.handselCourse;
					KK._studentBroadCast.schoolComment = rs.schoolComment;
					if(	KK._studentBroadCast.todayCurrCourse > 0 || KK._studentBroadCast.handselCourse > 0){
						$("#header-bar li.myCourse a").eq(0).append('<i class="icoR icoR_9"></i>');
					}
					var url=String(window.document.location.href);
					var allargs = url.split("?")[1]; 
					if(allargs == 'mod=student&act=index'){
						KK.buildBroadCast();
					}
				}
			});
		}else if(KK._config.broadCast == 'teacherIndex'){
			$.ajax({
				url : this._kkurl+"/?mod=common&act=data&do=getTeacherBroadCast&_r="+Math.random(),
				type : "get",
				dataType : "jsonp",
				jsonp : "jsonpcallback",
				timeout: 5000,
				success : function(rs){
					KK._teacherBroadCast.schoolInvite = rs.schoolInvite;
					KK.buildBroadCast();
				}
			});
		}else if(KK._config.broadCast == 'sellerIndex'){
			$.ajax({
				url : this._kkurl+"/?mod=common&act=data&do=getSellerBroadCast&_r="+Math.random(),
				type : "get",
				dataType : "jsonp",
				jsonp : "jsonpcallback",
				timeout: 5000,
				success : function(rs){
					KK._schoolBroadCast.teacherApply = rs.teacherApply;
					KK._schoolBroadCast.refundApply = rs.refundApply;
					KK._schoolBroadCast.student1v1 = rs.student1v1;
					KK.buildBroadCast();
				}
			});
		}
	},
	
	buildBroadCast:function(){
		if(KK._config.broadCast == 'studentIndex'){
			if(KK._studentBroadCast.todayCurrCourse > 0 || KK._studentBroadCast.handselCourse > 0 || KK._studentBroadCast.schoolComment > 0){
				var html = ['<section class="myck_item1 broadCast" style="display:none">',
							'<div class="message_box">',
							KK._studentBroadCast.todayCurrCourse > 0 ? '<a href="'+this._kkurl+'/?mod=student&act=course&do=timelist"><span class="f14"><i class="c_f60">'+KK._studentBroadCast.todayCurrCourse+'</i>节今日直播课</span></a>' : '',
							(KK._studentBroadCast.todayCurrCourse > 0 && KK._studentBroadCast.handselCourse > 0) ? '<i class="ml20 mr20 c_ccc">|</i>' : '',
							KK._studentBroadCast.handselCourse > 0 ? '<a href="'+this._kkurl+'/?mod=student&act=course&do=authorize"><span class="f14"><i class="c_f60">'+KK._studentBroadCast.handselCourse+'</i>个课程赠送</span></a>' : '',
							((KK._studentBroadCast.todayCurrCourse > 0 || KK._studentBroadCast.handselCourse > 0) && KK._studentBroadCast.schoolComment > 0) ? '<i class="ml20 mr20 c_ccc">|</i>' : '',
							KK._studentBroadCast.schoolComment > 0 ? '<a href="'+this._kkurl+'/?mod=student&act=credit&comment=1"><span class="f14"><i class="c_f60">'+KK._studentBroadCast.schoolComment+'</i>个学校评价</span></a>' : '',
							'</div></section>'].join('');
			}
		}else if(KK._config.broadCast == 'teacherIndex'){
			if(KK._teacherBroadCast.schoolInvite > 0){
				var html = ['<section class="myck_item1 broadCast mb20" style="display:none">',
							'<div class="message_box">',
							'<a href="'+this._kkurl+'/?mod=teacher&act=school&type=0"><span class="f14"><i class="c_f60">'+KK._teacherBroadCast.schoolInvite+'</i>个加盟邀请</span></a>',
							'</div></section>'].join('');
			}
		}else if(KK._config.broadCast == 'sellerIndex'){
			if(KK._schoolBroadCast.teacherApply > 0 || KK._schoolBroadCast.refundApply > 0 || KK._schoolBroadCast.student1v1 > 0 || KK._schoolBroadCast.studentComment > 0 || KK._schoolBroadCast.newOrderCnt > 0){
				var html = ['<section class="myck_item1 broadCast mb20" style="display:none">',
							'<div class="message_box">',
							KK._schoolBroadCast.teacherApply > 0 ? '<a href="'+this._kkurl+'/?mod=seller&act=teacher&do=sign&type=1"><span class="f14"><i class="c_f60">'+KK._schoolBroadCast.teacherApply+'</i>个加盟申请</span></a>' : '',
							(KK._schoolBroadCast.teacherApply > 0 && KK._schoolBroadCast.refundApply > 0) ? '<i class="ml20 mr20 c_ccc">|</i>' : '',
							KK._schoolBroadCast.refundApply > 0 ? '<a href="'+this._kkurl+'/?mod=seller&act=refund&do=list&status=1"><span class="f14"><i class="c_f60">'+KK._schoolBroadCast.refundApply+'</i>个退款申请</span></a>' : '',
							((KK._schoolBroadCast.teacherApply > 0 || KK._schoolBroadCast.refundApply > 0 ) && KK._schoolBroadCast.student1v1 > 0) ? '<i class="ml20 mr20 c_ccc">|</i>' : '',
							KK._schoolBroadCast.student1v1 > 0 ? '<a href="'+this._kkurl+'/?mod=1v1&act=seller&do=deploy&status=1"><span class="f14"><i class="c_f60">'+KK._schoolBroadCast.student1v1+'</i>个1对1新增订单</span></a>' : '',
							((KK._schoolBroadCast.teacherApply > 0 || KK._schoolBroadCast.refundApply > 0 || KK._schoolBroadCast.student1v1 > 0) && KK._schoolBroadCast.studentComment > 0) ? '<i class="ml20 mr20 c_ccc">|</i>' : '',
							KK._schoolBroadCast.studentComment > 0 ? '<a href="'+this._kkurl+'/?mod=seller&act=credit&comment=1"><span class="f14"><i class="c_f60">'+KK._schoolBroadCast.studentComment+'</i>个学生评价</span></a>' : '',
							((KK._schoolBroadCast.teacherApply > 0 || KK._schoolBroadCast.refundApply > 0 || KK._schoolBroadCast.student1v1 > 0 || KK._schoolBroadCast.studentComment > 0) && KK._schoolBroadCast.newOrderCnt > 0) ? '<i class="ml20 mr20 c_ccc">|</i>' : '',
							KK._schoolBroadCast.newOrderCnt > 0 ? '<a href="'+this._kkurl+'/?mod=seller&act=order"><span class="f14"><i class="c_f60">'+KK._schoolBroadCast.newOrderCnt+'</i>个新增的销售定单</span></a>' : '',	
							'</div></section>'].join('');
			}
		}
		$("div.pageContent").prepend(html);
		$(".broadCast").slideDown();
	},
	
	buildStudentMenu:function(){
		$.getJSON(this._kkurl+"/?mod=common&act=data&do=getStudentMenu&_r="+Math.random(), function(rs){
			var data = rs.data;
			for(var i in data){
				if (data[i] > 0) {
					KK.replaceMenu("studentMenu", i, data[i], "+");
				}
			}
		});
	},
	
	buildTeacherMenu:function(){
		$.getJSON(this._kkurl+"/?mod=common&act=data&do=getTeacherMenu&_r="+Math.random(), function(rs){
			var data = rs.data;
			for(var i in data){
				if (data[i] > 0) {
					KK.replaceMenu("teacherMenu", i, data[i], "+");
				}
			}
		});
	},
	
	buildSellerMenu:function(){
		$.getJSON(this._kkurl+"/?mod=common&act=data&do=getSellerMenu&_r="+Math.random(), function(rs){
			var data = rs.data;
			for(var i in data){
				if (data[i] > 0) {
					KK.replaceMenu("sellerMenu", i, data[i], "+");
				}
			}
		});
	},

	/**
	 * 用于页面操作引起的MENU的数值变化，可直接使用本方法动态修改
	 * step值为"+","-"，表示增加和减少val的值，
	 */
	replaceMenu:function(nodeId, itemClass, val, step){
		if (val <= 0) {
			return;
		}
		var itemNode = $("#"+nodeId+" a."+itemClass),
			itemText = itemNode.find('i.num').text();
		if (itemNode.find('i.num').length <= 0) {
			if (typeof step == 'undefined') {
				itemNode.append('<i class="num">（'+val+'）</i>');
			}else{
				if (step == "+") {
					itemNode.append('<i class="num">（'+val+'）</i>');
				}
			}
		}else{
			if (step == "+") {
				itemNode.find('i.num').text(itemText.replace(/\d+/, function(args){
					return (parseInt(args)+1);
				}));
			}else{
				if(parseInt(itemText.match(/\d+/)) - val <= 0){
					itemNode.find('i.num').remove();
				}else{
					itemNode.find('i.num').text(itemText.replace(/\d+/, function(args){
						return (parseInt(args)-1);
					}));
				}
			}
		}
	},

	readCookie:function(name) {
		var cookie = '';
		var search = name + '=';
		if (document.cookie.length > 0) {
			var offset = document.cookie.indexOf(search);
			if (offset != -1) {
				offset += search.length;
				var end = document.cookie.indexOf(";", offset);
				if (end == -1) {
					end = document.cookie.length;
				}
				cookie = document.cookie.substring(offset, end);
			}
		}
		return decodeURIComponent(cookie);
	},
	
	base64_decode:function(input) {
		var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
		var output = "";
		var chr1, chr2, chr3 = "";
		var enc1, enc2, enc3, enc4 = "";
		var i = 0;
		if (input.length % 4 != 0) {
			return "";
		}
		var base64test = /[^A-Za-z0-9\+\/\=]/g;
		if (base64test.exec(input)) {
			return "";
		}
		do {
			enc1 = keyStr.indexOf(input.charAt(i++));
			enc2 = keyStr.indexOf(input.charAt(i++));
			enc3 = keyStr.indexOf(input.charAt(i++));
			enc4 = keyStr.indexOf(input.charAt(i++));
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
			output = output + String.fromCharCode(chr1);
			if (enc3 != 64) {
				output+=String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output+=String.fromCharCode(chr3);
			}
			chr1 = chr2 = chr3 = "";
			enc1 = enc2 = enc3 = enc4 = "";
		} while (i < input.length);
		return output;
	},

	base64_encode:function(str) {
		var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
		var out, i, len;
		var c1, c2, c3;

		len = str.length;
		i = 0;
		out = "";
		while(i < len) {
			c1 = str.charCodeAt(i++) & 0xff;
			if(i == len) {
				out += base64EncodeChars.charAt(c1 >> 2);
				out += base64EncodeChars.charAt((c1 & 0x3) << 4);
				out += "==";
				break;
			}
			c2 = str.charCodeAt(i++);
			if(i == len) {
				out += base64EncodeChars.charAt(c1 >> 2);
				out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
				out += base64EncodeChars.charAt((c2 & 0xF) << 2);
				out += "=";
				break;
			}
			c3 = str.charCodeAt(i++);
			out += base64EncodeChars.charAt(c1 >> 2);
			out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
			out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6));
			out += base64EncodeChars.charAt(c3 & 0x3F);
		}
		return out;
	}
};
(function($, KK){
	$(function(){
		KK.init();
		setInterval("getrsp()",60000);
	})
})(jQuery, KK);

var _hmt = _hmt || [];
(function() {
   var hm = document.createElement("script");
   hm.src = "//hm.baidu.com/hm.js?2be0d6083ea4207036d33a4d8be519db";
   var s = document.getElementsByTagName("script")[0]; 
       s.parentNode.insertBefore(hm, s);
})();
